var app = getApp(), api = app.api, is_loading_more = !1, is_no_more = !1;

Page({
    data: {
        cat_id: 0, //类目ID
        type: 0, //0红包视频1普通视频
        page: 1,
        banner_list: [],
        list: [],
        no_more: !1,
        loading: !1,
    },
    onLoad: function(o) {
        app.page.onLoad(this, o);
        var a = this;
        a.setData({
            type: o.type || 0,
            cat_id: o.cat_id || 0
        }), a.loadBanner(), a.loadVideoList();
    },
    loadVideoList: function() {
        var a = this, c = wx.getStorageSync('city');
        a.data.no_more ? "function" == typeof t && t() : a.data.loading || (a.setData({
            loading: !0
        }), app.request({
            url: api.default.video_list_index,
            data: {
                page: a.data.page,
                cat_id: a.data.cat_id,
                type: a.data.type,
                cityname: c
            },
            success: function(t) {
                if(0 == t.code) {
                    if (!t.data.list || !t.data.list.length) return void a.setData({
                        no_more: !0,
                    });
                    a.data.list || (a.data.list = []), a.data.list = a.data.list.concat(t.data.list), 
                    a.setData({
                        list: a.data.list,
                        page: a.data.page + 1,
                    });
                }
            },
            complete: function() {
                a.setData({
                    loading: !1
                }), "function" == typeof t && t();
            }
        }));
    },
    loadBanner: function() {
        var a = this;
        app.request({
            url: api.default.banner_list,
            success: function(e) {
                0 == e.code && a.setData({
                    banner_list: e.data
                })
            }
        })
    },
    
    goto: function(o) {
        var id = o.currentTarget.dataset.id, mch_id = o.currentTarget.dataset.mch_id;
        wx.navigateTo({
          url: '/pages/video/video-view?id='+id+'&mch_id='+mch_id,
        })
    },

    catClick: function() {
        wx.navigateTo({
          url: '/pages/video/video-cat?cat_id=' + this.data.cat_id + '&type=' + this.data.type,
        })
    },

    sortClick: function(t) {
        console.log(t);
        var a = this, e = t.currentTarget.dataset.sort;
        a.setData({
            type: e,
            page: 1,
            list: [],
            no_more: !1,
        }), a.loadVideoList();
    },
    onReady: function() {},
    onShow: function() {
        app.page.onShow(this);
    },
    onHide: function() {
        app.page.onHide(this);
    },
    onUnload: function() {
        app.page.onUnload(this);
    },
    onPullDownRefresh: function() {},
    
    onReachBottom: function() {
       this.loadVideoList();
    },
    
});